<?php


namespace App\Controller\Client;


use App\Controller\AbstractController;
use App\Request\Client\Task\ListRequest;
use App\Request\Client\Task\ReceiverRequest;
use App\Request\Client\Task\ReceiveTaskListRequest;
use App\Request\Client\Task\ReceiveTaskRequest;
use App\Request\Client\Task\ReceiveTaskSubmitRequest;
use App\Service\Client\TaskService;
use Hyperf\Di\Annotation\Inject;

class TaskController extends AbstractController
{
    /**
     * @Inject()
     * @var TaskService
     */
    protected $taskService;

    /**
     * 随机任务
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function random()
    {
        $data = $this->taskService->random();
        return $this->response->success($data);
    }


    /**
     * 任务列表
     * @param ListRequest $request
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function list(ListRequest $request)
    {
        $validator = $request->validated();
        $data = $this->taskService->list($validator);
        return $this->response->success($data);
    }

    /**
     * 任务详情
     * @param $id
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function info($id)
    {
        $data = $this->taskService->info($id);
        return $this->response->success($data);
    }

    /**
     * 指定任务的用户信息
     * @param $id
     * @param ReceiverRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function receiver($id, ReceiverRequest $request)
    {
        $validator = $request->validated();
        $data = $this->taskService->receiver($id, $validator);
        return $this->response->success($data);
    }

    /**
     * 领取任务
     * @param ReceiveTaskRequest $request
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function receiveTask(ReceiveTaskRequest $request)
    {
        $validator = $request->validated();
        $data = $this->taskService->receiveTask($validator);
        return $this->response->success($data);
    }

    /**
     * 任务列表-已经领取
     * @param ReceiveTaskListRequest $request
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function receiveTaskList(ReceiveTaskListRequest $request)
    {
        $validator = $request->validated();
        $data = $this->taskService->receiveTaskList($validator);
        return $this->response->success($data);
    }


    /**
     * 提交/修改任务
     * @param $id
     * @param ReceiveTaskSubmitRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Throwable
     */
    public function receiveTaskSubmit($id, ReceiveTaskSubmitRequest $request)
    {
        $validator = $request->validated();
        $this->taskService->receiveTaskSubmit($id, $validator);
        return $this->response->success();
    }


    /**
     * 申请仲裁
     * @param $id
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function receiveTaskArbitrate($id)
    {
        $this->taskService->receiveTaskArbitrate($id);
        return $this->response->success();
    }

    /**
     * 任务标签
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function tags()
    {
        $data = $this->taskService->tags();
        return $this->response->success($data);
    }


    /**
     * 任务进度-详情
     * @param $id
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function processInfo($id)
    {
        $data = $this->taskService->processInfo($id);
        return $this->response->success($data);
    }


    /**
     * 通过主任务id获取领取情况
     * @param $id
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function taskReceiverInfo($id){
        $data = $this->taskService->taskReceiverInfo($id);
        return $this->response->success($data);
    }


}